<template>
  <div class="personal-container">
    <!-- 顶部标题 -->
    <div class="header">
      <h2>个人信息</h2>
      <el-button @click="goBack" type="primary" size="small" plain>返回</el-button>
    </div>

    <!-- 用户信息卡片 -->
    <el-card class="info-card">
      <el-descriptions :column="1" border>
        <el-descriptions-item label="用户名">{{ userInfo.username }}</el-descriptions-item>
        <el-descriptions-item label="姓名">{{ userInfo.name }}</el-descriptions-item>
        <el-descriptions-item label="邮箱">{{ userInfo.email }}</el-descriptions-item>
        <el-descriptions-item label="角色">
          {{ userInfo.role === 'admin' ? '管理员' : '普通用户' }}
        </el-descriptions-item>
      </el-descriptions>
    </el-card>

    <!-- 退出登录按钮 -->
    <div class="logout-wrapper">
      <el-button type="danger" @click="handleLogout" round>退出登录</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useUser } from '@/components/composables/usePersonalInfo'

const { userInfo, handleLogout, goBack } = useUser()
</script>

<style scoped>
.personal-container {
  padding: 30px;
  background-color: #f9f9f9;
  min-height: 100vh;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.header h2 {
  font-size: 24px;
  color: #333;
}

.info-card {
  max-width: 600px;
  margin: 0 auto;
}

.logout-wrapper {
  display: flex;
  justify-content: center;
  margin-top: 30px;
}

.el-button {
  padding: 12px 24px;
  font-size: 16px;
}
</style>
